﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace commodity.Migrations
{
    public partial class OneMigration : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "Commodities",
                columns: table => new
                {
                    id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    CommodityName = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Commodities", x => x.id);
                });

            migrationBuilder.CreateTable(
                name: "FirstsCommodityMenus",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_FirstsCommodityMenus", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "CommodityInformations",
                columns: table => new
                {
                    id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    PropertyName = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: false),
                    Value = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    state = table.Column<int>(type: "int", nullable: false),
                    CommodityId = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CommodityInformations", x => x.id);
                    table.ForeignKey(
                        name: "FK_CommodityInformations_Commodities_CommodityId",
                        column: x => x.CommodityId,
                        principalTable: "Commodities",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "goods",
                columns: table => new
                {
                    Goods_Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Goods_Name = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: false),
                    Goods_Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    Goods_Number = table.Column<int>(type: "int", nullable: false),
                    CreateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdateTime = table.Column<DateTime>(type: "datetime2", nullable: false),
                    CommodityId = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_goods", x => x.Goods_Id);
                    table.ForeignKey(
                        name: "FK_goods_Commodities_CommodityId",
                        column: x => x.CommodityId,
                        principalTable: "Commodities",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "SecondCommodityMenus",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Name = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: false),
                    FirstsCommodityMenuId = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SecondCommodityMenus", x => x.Id);
                    table.ForeignKey(
                        name: "FK_SecondCommodityMenus_FirstsCommodityMenus_FirstsCommodityMenuId",
                        column: x => x.FirstsCommodityMenuId,
                        principalTable: "FirstsCommodityMenus",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "goodsInformations",
                columns: table => new
                {
                    id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    PropertyName = table.Column<string>(type: "nvarchar(32)", maxLength: 32, nullable: false),
                    Value = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    state = table.Column<int>(type: "int", nullable: false),
                    GoodsId = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_goodsInformations", x => x.id);
                    table.ForeignKey(
                        name: "FK_goodsInformations_goods_GoodsId",
                        column: x => x.GoodsId,
                        principalTable: "goods",
                        principalColumn: "Goods_Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "goodsPictures",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    Path = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    GoodsId = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_goodsPictures", x => x.Id);
                    table.ForeignKey(
                        name: "FK_goodsPictures_goods_GoodsId",
                        column: x => x.GoodsId,
                        principalTable: "goods",
                        principalColumn: "Goods_Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "SecondCommodityMenuCommodity",
                columns: table => new
                {
                    SecondCommodityMenuId = table.Column<int>(type: "int", nullable: false),
                    CommodityId = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_SecondCommodityMenuCommodity", x => new { x.SecondCommodityMenuId, x.CommodityId });
                    table.ForeignKey(
                        name: "FK_SecondCommodityMenuCommodity_Commodities_CommodityId",
                        column: x => x.CommodityId,
                        principalTable: "Commodities",
                        principalColumn: "id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_SecondCommodityMenuCommodity_SecondCommodityMenus_SecondCommodityMenuId",
                        column: x => x.SecondCommodityMenuId,
                        principalTable: "SecondCommodityMenus",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_CommodityInformations_CommodityId",
                table: "CommodityInformations",
                column: "CommodityId");

            migrationBuilder.CreateIndex(
                name: "IX_goods_CommodityId",
                table: "goods",
                column: "CommodityId");

            migrationBuilder.CreateIndex(
                name: "IX_goodsInformations_GoodsId",
                table: "goodsInformations",
                column: "GoodsId");

            migrationBuilder.CreateIndex(
                name: "IX_goodsPictures_GoodsId",
                table: "goodsPictures",
                column: "GoodsId");

            migrationBuilder.CreateIndex(
                name: "IX_SecondCommodityMenuCommodity_CommodityId",
                table: "SecondCommodityMenuCommodity",
                column: "CommodityId");

            migrationBuilder.CreateIndex(
                name: "IX_SecondCommodityMenus_FirstsCommodityMenuId",
                table: "SecondCommodityMenus",
                column: "FirstsCommodityMenuId");
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "CommodityInformations");

            migrationBuilder.DropTable(
                name: "goodsInformations");

            migrationBuilder.DropTable(
                name: "goodsPictures");

            migrationBuilder.DropTable(
                name: "SecondCommodityMenuCommodity");

            migrationBuilder.DropTable(
                name: "goods");

            migrationBuilder.DropTable(
                name: "SecondCommodityMenus");

            migrationBuilder.DropTable(
                name: "Commodities");

            migrationBuilder.DropTable(
                name: "FirstsCommodityMenus");
        }
    }
}
